package net.oschina.simpleplus;

/**
 * @author ; simpleplus(simpleplus@sina.cn)
 */
public abstract class DelayedAction extends Action{
    private final long execTime;

    private volatile boolean cancel;

    public DelayedAction(long execTime, ActionQueue queue) {
        super(queue);
        if(execTime == 0){
            checkin();
            this.execTime = 0;

        }else{
            this.execTime = execTime + System.currentTimeMillis();
            queue.checkinDelayedAction(this);
        }
    }


    public boolean tryExec(long currTime){
        if(cancel){
            return true;
        }

        if(currTime >= execTime){
            checkin();
            return true;
        }
        return false;
    }
}
